package it.polimi.traveldream;

import it.polimi.traveldream.entities.Hotel;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.Query;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;


/**
 * Session Bean implementation class GestioneShowHotel
 */
@Stateless
public class GestioneShowHotel implements GestioneShowHotelLocal {

	@PersistenceContext
    private EntityManager em;
	
    /**
     * Default constructor. 
     */
    public GestioneShowHotel() {
        // TODO Auto-generated constructor stub
    }
    
    @Override
    public List<HotelDTO> showHotel(){
    	Query q = em.createNamedQuery("Hotel.findAll");
    	return convert(q.getResultList());
    }
    
    public List<HotelDTO> convert(List<Hotel> list1){
    	List<HotelDTO>tmp=new ArrayList<HotelDTO>();
    	
    	for(Hotel h: list1){
    		HotelDTO htmp=new HotelDTO();
    		htmp.setId(h.getId());
    		htmp.setName(h.getName());
    		htmp.setDescription(h.getDescription());
    		htmp.setIndirizzo(h.getIndirizzo());
    		htmp.setPrice(h.getPrice());
    		htmp.setStelle(h.getStelle());
    		tmp.add(htmp);
    	}
    	
    	return tmp;
    	
    }

}
